Skip to content

Additionally support Postgis Geography codec under one generic PostgisCodec - #727

Open
mdedetrich wants to merge 1 commit into
pgjdbc:mainfrom
mdedetrich:add-postgis-geography
Open

Additionally support Postgis Geography codec under one generic PostgisCodec#727
mdedetrich wants to merge 1 commit into
pgjdbc:mainfrom
mdedetrich:add-postgis-geography

Conversation

@mdedetrich

@mdedetrich mdedetrich commented Jul 8, 2026

Copy link
Copy Markdown

Make sure that:

  • You have read the contribution guidelines.
  • You have created a feature request first to discuss your contribution intent. Please reference the feature request ticket number in the pull request.
  • You use the code formatters provided here and have them applied to your changes. Don't submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.

Issue description

Resolves: #528

New Public APIs

PostgisGeographyCodec (if this counts as an API).

Additional context

Note that the implementation does have a fair bit of boilerplate due to PostgisGeographyCodec being final and hence not being able to be subclassed. One alternative would be to have a package private implementation that both PostgisGeographyCodec and PostgisGeometryCodec can share (that way both PostgisGeographyCodec and PostgisGeometryCodec can be final).

As suggested in the linked github issue, the implementation is just a copy paste of PostgisGeometryCodec that also uses the org.locationtech.jts.geom.Geometry but this allows you to decode postgres geography types.

@mdedetrich
mdedetrich force-pushed the add-postgis-geography branch from 3ec52e3 to 64f447d Compare July 8, 2026 18:18
@mdedetrich
mdedetrich force-pushed the add-postgis-geography branch 2 times, most recently from 8d0e343 to 548ad38 Compare July 29, 2026 17:19
@mdedetrich

mdedetrich commented Jul 29, 2026

Copy link
Copy Markdown
Author

After realizing an issue with this implementation, specifically that encoding an object using Codec.canEncode(Object value), would have gotten surprising results into how that object would have been encoded depending on what order DefaultCodecLookup.findEncodeCodec finds them due to having multiple codecs sharing the JTS Geography type.

Given that, I opted for a design that is more semantically correct, i.e. treat Geography the same way that String is treated and make a generic PostgisCodec that supports both geography and geometry in the same way String supports multiple types (VARCHAR, TEXT, NAME etc etc).

This did require touching some other internals i.e. BuiltinDynamicCodecs had to be updated to support retrieving multiple oid's from multiple rows and join them into a single codec (currently only supported one oid per row), but I think the end result is cleaner, better and more idiomatic as just like String, the only difference between Geography and Geometry are internal differences in how Postgres calculates distances, but they both fundamentally represent the same type on a client.

@mdedetrich mdedetrich changed the title Add Postgis Geography codec Support Postgis Geography codec under one PostgisCodec Jul 29, 2026
@mdedetrich
mdedetrich force-pushed the add-postgis-geography branch 2 times, most recently from f0937db to f03ef79 Compare July 29, 2026 18:22
@mdedetrich
mdedetrich force-pushed the add-postgis-geography branch from f03ef79 to 8493054 Compare July 29, 2026 18:25
@mdedetrich mdedetrich changed the title Support Postgis Geography codec under one PostgisCodec Additionally support Postgis Geography codec under one generic PostgisCodec Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add geography data type support

1 participant